Skip to content

Finished Practice PR#8

Open
Butenkite wants to merge 12 commits intogrc-cohort-21:mainfrom
Butenkite:main
Open

Finished Practice PR#8
Butenkite wants to merge 12 commits intogrc-cohort-21:mainfrom
Butenkite:main

Conversation

@Butenkite
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@auberonedu auberonedu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! See feedback in the comments below.

Comment thread src/ListPractice.java
public static void main(String[] args) {
// Create an empty ArrayList of Strings and assign it to a variable of type List

ArrayList<String> list = new ArrayList<String>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to use interface types where appropriate (List)

Comment thread src/MapPractice.java
Comment on lines +32 to +34
for(String entry : mapsPractice.keySet()){
System.out.println("Key: " + entry + ". Value: " + mapsPractice.get(entry));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works! In the future, also consider entrySet

Comment thread src/Person.java
Comment on lines +11 to +12
public String name = "";
private int age = -99;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these it's probably best not to set the defaults. They will automatically default to null and 0.

Comment thread src/Person.java
Comment on lines +16 to +19
public Person(String x, int y){
name = x;
age = y;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but try to use more descriptive variable names in the future. A caller of this class will be confused as to what x and y represent.

Comment thread src/Person.java
Comment on lines +39 to +41
public int birthYear(int currentYear){
return(currentYear - age);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere we don't need the parentheses after return. You can just say return currentYear - age;

Comment thread src/Person.java
Comment on lines +43 to +45
public String getName(){
return(name);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need getters for a public instance variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants